<?php

namespace app\admin\controller;
use app\admin\model\OrderModel;
use app\common\controller\AdminBaseController;
use think\Db;
/**
 * 订单统计
 */
class OrderEnterController extends AdminBaseController
{
 	protected $model;
	
    protected function _initialize() {
        parent::_initialize();
        $this->model = new OrderModel();
    }
    /**
     *线上 订单统计
     * @author [lx] 
     */
    public function index( $page = 1){
    	
		//本日订单统计
		$todaysum = Db::name("mall_order")->whereTime('order_time','today')->count('id');
        $this->assign('todaysum',$todaysum);
        
		//本周订单统计
		$weeksum = Db::name("mall_order")->whereTime('order_time','week')->count('id');
        $this->assign('weeksum',$weeksum);
		
		//本月订单统计
		$monthsum = Db::name("mall_order")->whereTime('order_time','month')->count('id');
        $this->assign('monthsum',$monthsum);
		
		//下单订单统计
		$sum = Db::name("mall_order")->count('id');
        $this->assign('sum',$sum);
        
        //今日下单笔数统计
         $xiadan=[];
         for($i=0;$i<7;$i++){
        	$time=date('Y-m-d',strtotime(-$i.'day'));
        	$where['order_time']=['like','%'.$time.'%'];
      		$xiadan[$i] = Db::name("mall_order")->where($where)->count("id");
		}
		
        $this->assign('xiadan',$xiadan); 
        
        //付款订单统计
		 $fukuan=[];
        for($i=0;$i<7;$i++){
        	$time=date('Y-m-d',strtotime(-$i.'day'));
        	$where['order_time']=['like','%'.$time.'%'];
      		$fukuan[] = Db::name("mall_order")->where('order_state!=1')->where($where)->count("id");
		}
        $this->assign('fukuan',$fukuan);
        
       // 发货订单统计
        $fahuo=[];
        for($i=0;$i<7;$i++){
          $time=date('Y-m-d',strtotime(-$i.'day'));
          $where['order_time']=['like','%'.$time.'%'];
          $fahuo[] = Db::name("mall_order")->where('order_state!=1')->where('order_state!=2')->where('order_state!=3')->where($where)->count('id'); 
        }
      $this->assign('fahuo',$fahuo);
      return $this->fetch('index',['xiadan' => $xiadan,'fukuan'=> $fukuan,'fahuo'=> $fahuo]);
    }
}
